package com.lingxu.module.earlyWarn.controller;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.system.fileManage.entity.SysFileInfo;
import com.lingxu.base.system.fileManage.service.SysFileInfoService;
import com.lingxu.module.earlyWarn.entity.IssueManage;
import com.lingxu.module.earlyWarn.entity.IssueManageBook;
import com.lingxu.module.earlyWarn.entity.IssueParams;
import com.lingxu.module.earlyWarn.service.EarlyWarnProbManageService;
import com.lingxu.module.earlyWarn.service.IssueManageSercvice;
import com.lingxu.module.earlyWarn.service.ModelIssueCaredSercvice;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@Api(tags="预警问题管理")
@RestController
@RequestMapping(value = "/earlyWarn")
public class EarlyWarnProbManageController {

    @Autowired
    private EarlyWarnProbManageService earlyWarnProbManageService;
    @Autowired
    private IssueManageSercvice issueManageSercvice;
    @Autowired
    private SysFileInfoService sysFileInfoService;
    @Autowired
    private ModelIssueCaredSercvice modelIssueCaredSercvice;

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询问题列表
     * @Date 2024/1/3 10:33
     * @Param: params
     **/
    @RequestMapping(value = "/findModelIssueList")
    public Result findModelIssueList(@RequestBody IssueParams params) {
        return earlyWarnProbManageService.findModelIssueList(params);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 修改问题数据列表中的一些状态:已关闭、以免查
     * @Date 2024/1/3 16:15
     * @Param: manage
     **/
    @RequestMapping(value = "/updateIssueDataStatus")
    public Result updateIssueDataStatus(@RequestBody IssueManage manage) {
        if ("已免查".equals(manage.getDisposalStatus())) {
            manage.setIsExempt("1");
        }
        issueManageSercvice.updateById(manage);
        return Result.ok("操作成功");
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询江苏省区划
     * @Date 2024/1/4 10:05
     * @Param:
     **/
    @RequestMapping(value = "/findRegionTree")
    public Result findRegionTree() {
        return issueManageSercvice.findRegionTree();
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 新增问题办理
     * @Date 2024/1/3 17:53
     * @Param: issueHandle
     **/
    @RequestMapping(value = "/addIssueHandle")
    public Result addIssueHandle(@RequestBody IssueManage issueManage) {
        return issueManageSercvice.addIssueHandle(issueManage);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询问题详情
     * @Date 2024/1/4 17:22
     * @Param: id
     **/
    @RequestMapping(value = "/findIssueDataInfo")
    public Result findIssueDataInfo(String id) {
        IssueManage manage = issueManageSercvice.getById(id);
        //查询文件
        List<SysFileInfo> fileInfos = sysFileInfoService.findFileInfoByRecord(id, "1");
        manage.setFileInfoList(fileInfos);
        return Result.ok(manage, "查询成功");
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 统计已审批、未审批数量
     * @Date 2024/1/9 14:51
     * @Param: params
     **/
    @RequestMapping(value = "/findIssueHandleNeedApprovalCount")
    public Result findIssueHandleNeedApprovalCount(@RequestBody IssueParams params) {
        return issueManageSercvice.findIssueHandleNeedApprovalCount(params);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询需要领导审批的问题办理
     * @Date 2024/1/8 10:43
     * @Param: params
     **/
    @RequestMapping(value = "/findIssueHandleNeedApproval")
    public Result findIssueHandleNeedApproval(@RequestBody IssueParams params) {
        return issueManageSercvice.findIssueHandleNeedApproval(params);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 领导审批
     * @Date 2024/1/8 11:36
     * @Param: manage
     **/
    @RequestMapping(value = "/leaderApproval")
    public Result leaderApproval(@RequestBody IssueManage manage) {
        return issueManageSercvice.leaderApproval(manage);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 下级退回
     * @Date 2024/1/8 11:45
     * @Param: manage
     **/
    @RequestMapping(value = "/subordinateBack")
    public Result subordinateBack(@RequestBody IssueManage manage) {
        return issueManageSercvice.subordinateBack(manage);
    }


    /**
     * @return void
     * @Author ysj闫世杰
     * @Description 导出Excel问题数量
     * @Date 2024/1/4 17:39
     * @Param: modelIds
     **/
    @RequestMapping(value = "/exportExcelFile")
    public void exportExcelFile(String modelId, String issueId, HttpServletResponse response) {
        issueManageSercvice.exportExcelFile(modelId, issueId, response);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询已添加、未添加标签
     * @Date 2024/1/3 17:56
     * @Param:
     **/
    @RequestMapping(value = "/findTagInAndOut")
    public Result findTagInAndOut(String issueId) {
        return issueManageSercvice.findTagInAndOut(issueId);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 批量转办
     * @Date 2024/1/5 14:59
     * @Param: params
     **/
    @RequestMapping(value = "/issueTransferBatch")
    public Result issueTransferBatch(@RequestBody IssueParams params) {
        return issueManageSercvice.issueTransferBatch(params);
    }

    /**
     * 拆分问题之后转办
     * @param params
     * @return
     */
    @RequestMapping(value = "/issueTransfer")
    public Result issueTransfer(@RequestBody IssueParams params) {
        return issueManageSercvice.issueTransfer(params);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 核查列表
     * @Date 2024/1/5 16:34
     * @Param: params
     **/
    @RequestMapping(value = "/findIssueCheckedList")
    public Result findIssueCheckedList(@RequestBody IssueParams params) {
        return issueManageSercvice.findIssueCheckedList(params);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 核查办理·
     * @Date 2024/1/8 9:15
     * @Param: manage
     **/
    @RequestMapping(value = "/issueCheckedHandler")
    public Result issueCheckedHandler(@RequestBody IssueManage manage) {
        return issueManageSercvice.issueCheckedHandler(manage);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 上传审批单
     * @Date 2024/1/8 9:43
     * @Param: manage
     **/
    @RequestMapping(value = "/uploadApprovalOrder")
    public Result uploadApprovalOrder(@RequestBody IssueManage manage) {
        return issueManageSercvice.uploadApprovalOrder(manage);
    }

    /**
     * 上传典型案例附件
     * @param manage
     * @return
     */
    @RequestMapping(value = "/uploadTypicalCasesAnnex")
    public Result uploadTypicalCasesAnnex(@RequestBody IssueManage manage) {
        return issueManageSercvice.uploadTypicalCasesAnnex(manage);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询审批单
     * @Date 2024/1/9 11:28
     * @Param: id
     **/
    @RequestMapping(value = "/findApprovalOrder")
    public Result findApprovalOrder(String id) {
        return issueManageSercvice.findApprovalOrder(id);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 办理结果
     * @Date 2024/1/8 16:30
     * @Param: manage
     **/
    @RequestMapping(value = "/updateIssueResults")
    public Result updateIssueResults(@RequestBody IssueManage manage) {
        return issueManageSercvice.updateIssueResults(manage);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 办结批量
     * @Date 2024/1/10 9:28
     * @Param: params
     **/
    @RequestMapping(value = "/updateIssueOverBatch")
    public Result updateIssueOverBatch(@RequestBody IssueParams params) {
        return issueManageSercvice.updateIssueOverBatch(params);
    }


    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 保存审批单数据
     * @Date 2024/1/12 11:37
     * @Param: manageBook
     **/
    @RequestMapping(value = "/saveApprovalOrder")
    public Result saveApprovalOrder(@RequestBody IssueManageBook manageBook) {
        return issueManageSercvice.saveApprovalOrder(manageBook);
    }

    /**
     * @return com.lingxu.base.common.api.vo.Result
     * @Author ysj闫世杰
     * @Description 查询审批单数据
     * @Date 2024/1/12 11:38
     * @Param: manageId
     **/
    @RequestMapping(value = "/findApprovalOrderData")
    public Result findApprovalOrderData(String manageId) {
        return issueManageSercvice.findApprovalOrderData(manageId);
    }

    /**
     * 问题关注 1关注 0取消关注
     * @param issueid
     * @param cared
     * @param userid
     * @return
     */
    @RequestMapping(value = "/careIssue")
    public Result careIssue(String issueid, String cared, String userid) {
        if ("1".equals(cared)) {
            return modelIssueCaredSercvice.addModelIssueCared(issueid, userid);
        } else {
            return  modelIssueCaredSercvice.deleteModelIssueCared(issueid, userid);
        }
    }

    /**
     * 问题转办页面，问题拆分
     * @param modelId
     * @param issueId
     * @return
     */
    @RequestMapping(value = "/issueSplitBySssjly")
    public Result issueSplitBySssjly(String modelId, String issueId) {
        return issueManageSercvice.issueSplitBySssjly(modelId,issueId);
    }

    /**
     * 获取当前模型的问题来源表
     * @param modelId
     * @return
     */
    @RequestMapping(value = "/getHaveTableListByModelId")
    public Result getHaveTableListByModelId(String modelId) {
        return issueManageSercvice.getHaveTableListByModelId(modelId);
    }

    @RequestMapping("/deleteIssueManageByModelId")
    public  Result deleteIssueManageByModelId(String modelId){
        return issueManageSercvice.deleteIssueManageByModelId(modelId);
    }

}
